<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="客户名称">
              <a-input placeholder="请输入客户名称" v-model="queryParam.custFullName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="客户级别">
              <j-dict-select-tag placeholder="请选择客户级别" v-model="queryParam.custLevel" dictCode="mdm_cust_level"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="成交状态">
                <j-dict-select-tag placeholder="请选择成交状态" v-model="queryParam.tradeStatusCode" dictCode="mdm_trade_status"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="负责人">
                <j-select-user-by-dep placeholder="请选择负责人" v-model="queryParam.owner" :multi="false"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" v-has="'customer:add'" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('客户')" v-has="'customer:exp'" >导出</a-button>
      <a-upload name="file" v-has="'customer:imp'"  :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" v-has="'customer:delBatch'" ><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="custFullName" slot-scope="text, record">
          <a @click="handleDrawerDetail(record)"><j-ellipsis :value="text" :length="12"/></a>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleDrawerDetail(record)">详情</a>
          <span v-has="'customer:edit'" >
            <a-divider type="vertical" />
            <a @click="handleEdit(record)">编辑</a>
          </span>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item  v-has="'customer:del'">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        <!-- 字符串超长截取省略号显示-->
        <span slot="custWebSite" slot-scope="text">
          <j-ellipsis :value="text" :length="30"/>
        </span>
        <!-- 字符串超长截取省略号显示-->
        <span slot="custAddress" slot-scope="text">
          <j-ellipsis :value="text" :length="12"/>
        </span>
        <span slot="custSaleArea" slot-scope="text">
          <j-ellipsis :value="text" :length="12"/>
        </span>
        <span slot="invTel" slot-scope="text">
          <j-ellipsis :value="text" :length="15"/>
        </span>
        <span slot="invTel" slot-scope="text">
          <j-ellipsis :value="text" :length="15"/>
        </span>
        <span slot="remark" slot-scope="text">
          <j-ellipsis :value="text" :length="20"/>
        </span>
      </a-table>
    </div>

    <mdm-customer-modal ref="modalForm" @ok="modalFormOk"></mdm-customer-modal>
    <mdm-customer-modal-drawer ref="modalFormDrawer" @ok="modalFormOk"></mdm-customer-modal-drawer>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import MdmCustomerModal from './modules/MdmCustomerModal'
  import MdmCustomerModalDrawer from './modules/MdmCustomerModal.Style#Drawer'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import Area from '@/components/_util/Area'

  export default {
    name: 'MdmCustomerList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      MdmCustomerModal,
      MdmCustomerModalDrawer,
      JEllipsis
    },
    data () {
      return {
        description: '客户管理页面',
        // 表头
        columns: [
          {
            title:'客户名称',
            align:"center",
            dataIndex: 'custFullName',
            width: 120,
            scopedSlots: { customRender: 'custFullName' }
          },
          {
            title:'客户级别',
            align:"center",
            dataIndex: 'custLevel_dictText',
            width:100
          },
          {
            title:'企业性质',
            align:"center",
            dataIndex: 'entTypeCode_dictText',
            width:100
          },
          {
            title:'销售区域',
            align:"center",
            dataIndex: 'custSaleArea',
            width:120,
            scopedSlots: { customRender: 'custSaleArea' }
          },
          {
            title:'省市区',
            align:"center",
            dataIndex: 'administrativeArea',
            width:120,
            scopedSlots: {customRender: 'pcaSlot'}
          },
          {
            title:'详细地址',
            align:"center",
            dataIndex: 'custAddress',
            width:160,
            scopedSlots: { customRender: 'custAddress' }
          },
          {
            title:'成交状态',
            align:"center",
            dataIndex: 'tradeStatusCode_dictText',
            width:100
          },
          {
            title:'负责人',
            align:"center",
            dataIndex: 'owner_dictText',
            width:100
          },
          {
            title:'负责所在部门',
            align:"center",
            dataIndex: 'ownerDept_dictText',
            width:120
          },
          {
            title:'客户上级单位',
            align:"center",
            dataIndex: 'custParentUnit_dictText',
            width:120
          },
          {
            title:'客户行业',
            align:"center",
            dataIndex: 'cateTypeCode_dictText',
            width:120
          },
          {
            title:'客户来源',
            align:"center",
            dataIndex: 'custSource_dictText',
            width:120
          },
          {
            title:'电话',
            align:"center",
            dataIndex: 'invTel',
            scopedSlots: { customRender: 'invTel' }
          },
          {
            title:'网址',
            align:"center",
            dataIndex: 'custWebSite',
            scopedSlots: { customRender: 'custWebSite' },
          },
          {
            title:'成立时间',
            align:"center",
            dataIndex: 'custSetTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            },
            width:100
          },
          {
            title:'注册资金',
            align:"center",
            dataIndex: 'custRegistCapital',
            width:100
          },
          {
            title:'邮编',
            align:"center",
            dataIndex: 'postCode',
            width:100
          },
          {
            title:'Email',
            align:"center",
            dataIndex: 'email',
            width:100
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark',
            width:160,
            scopedSlots: { customRender: 'remark' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/mdm/customer/list",
          delete: "/mdm/customer/delete",
          deleteBatch: "/mdm/customer/deleteBatch",
          exportXlsUrl: "/mdm/customer/exportXls",
          importExcelUrl: "mdm/customer/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.pcaData = new Area()
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      getPcaText(code){
        return this.pcaData.getText(code);
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'custNo',text:'客户编码',dictCode:''})
        fieldList.push({type:'string',value:'custFullName',text:'客户名称',dictCode:''})
        fieldList.push({type:'string',value:'custShortName',text:'客户简称',dictCode:''})
        fieldList.push({type:'string',value:'custAddress',text:'详细地址',dictCode:''})
        fieldList.push({type:'date',value:'custSetTime',text:'成立时间'})
        fieldList.push({type:'BigDecimal',value:'custRegistCapital',text:'注册资金',dictCode:''})
        fieldList.push({type:'string',value:'custWebSite',text:'网址',dictCode:''})
        fieldList.push({type:'string',value:'custLevel',text:'客户级别',dictCode:'mdm_cust_level'})
        fieldList.push({type:'string',value:'custSaleArea',text:'销售区域',dictCode:''})
        fieldList.push({type:'string',value:'custNationCode',text:'国别',dictCode:'mdm_cust_nation'})
        fieldList.push({type:'string',value:'custParentUnit',text:'客户上级单位',dictCode:''})
        fieldList.push({type:'string',value:'custSource',text:'客户来源',dictCode:'mdm_cust_source'})
        fieldList.push({type:'string',value:'tradeStatusCode',text:'成交状态',dictCode:'mdm_trade_status'})
        fieldList.push({type:'string',value:'cateScope',text:'经营范围',dictCode:''})
        fieldList.push({type:'string',value:'cateTypeCode',text:'客户行业',dictCode:'mdm_cust_cate'})
        fieldList.push({type:'string',value:'entTypeCode',text:'企业性质',dictCode:'mdm_ent_type'})
        fieldList.push({type:'string',value:'invBankNo',text:'银行账号',dictCode:''})
        fieldList.push({type:'string',value:'invBankName',text:'开户银行',dictCode:''})
        fieldList.push({type:'string',value:'invTaxNo',text:'纳税人识别号',dictCode:''})
        fieldList.push({type:'string',value:'invAddr',text:'地址',dictCode:''})
        fieldList.push({type:'string',value:'invTel',text:'电话',dictCode:''})
        fieldList.push({type:'string',value:'province',text:'省'})
        fieldList.push({type:'string',value:'city',text:'市',dictCode:''})
        fieldList.push({type:'string',value:'area',text:'区县',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'string',value:'owner',text:'负责人',dictCode:''})
        fieldList.push({type:'string',value:'ownerDept',text:'负责所在部门',dictCode:''})
        this.superFieldList = fieldList
      },
      handleDrawerDetail(record){
        this.$refs.modalFormDrawer.edit(record);
        this.$refs.modalFormDrawer.title="详情";
        this.$refs.modalFormDrawer.disableSubmit = true;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>